package com.lsq.baseadmin.modules.manage.utils;

import com.lsq.baseadmin.common.constant.ConstantSystem;
import com.lsq.baseadmin.modules.manage.vo.UserVo;

import javax.servlet.http.HttpSession;

/**
 * @author pc12138
 * @since 2020/10/24 11:53
 */
public class AuthUtil {

    public static void setLoginUser(UserVo userVo, HttpSession session) {
        session.setAttribute(ConstantSystem.SESSION_LOGIN_USER, userVo);
    }

    public static UserVo getLoginUser(HttpSession session) {
        return (UserVo) session.getAttribute(ConstantSystem.SESSION_LOGIN_USER);
    }

    public static void removeLoginUser(HttpSession session) {
        session.removeAttribute(ConstantSystem.SESSION_LOGIN_USER);
    }

    public static void setVerifyCode(String code, HttpSession session) {
        session.setAttribute(ConstantSystem.SESSION_VERIFY_CODE, code);
    }

    public static String getVerifyCode(HttpSession session) {
        return (String)session.getAttribute(ConstantSystem.SESSION_VERIFY_CODE);
    }

    /**
     *  还原密码: 前端传过来的密码将 %2B 替换为 +
     * @param password String
     */
    public static String convertPassword(String password) {
        return password.replaceAll("%2B","+");
    }

}
